Package edu.claflin.finder.struct
Class DisjointSet<T extends Comparable<T>>
java.lang.Object
edu.claflin.finder.struct.DisjointSet<T>
A LinkedList-based Disjoint Set data structure.
Three operations combined O(m * + n* log(n)).
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanWhether the given object is in the disjoint sets.booleandisjointElements(T a, T b) Whether two given elements are not in the same setprivate TGet the representative of the set the given object is in.voidCreate a new disjoint set with the given element.voidMerge the disjoint sets two elements are inintsize()Get the number of disjoint sets.toString()
-
Field Details
-
list
-
size
private int size -
length
private int length
-
-
Constructor Details
-
DisjointSet
public DisjointSet(int size)
-
-
Method Details
-
size
public int size()Get the number of disjoint sets.- Returns:
- the number of disjoint sets
-
contains
Whether the given object is in the disjoint sets.- Parameters:
a- the object to determined whether it is in the disjoint sets- Returns:
- true if the object is in the disjoint set, false otherwise
-
makeSet
Create a new disjoint set with the given element.- Parameters:
n- the new element
-
find
Get the representative of the set the given object is in.- Parameters:
x- the object to find the representative of- Returns:
- the representative
-
disjointElements
Whether two given elements are not in the same set- Parameters:
a- the first elementb- the second element- Returns:
- whether the elements are not in the same set
-
merge
Merge the disjoint sets two elements are in- Parameters:
a- the first elementb- the second element
-
toString
-